package com.slipper.system.menu.front;

import com.slipper.common.bo.Result;
import com.slipper.common.util.ResultUtil;
import com.slipper.system.menu.service.MenuPrivilegeService;
import com.slipper.system.menu.service.MenuService;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import com.slipper.system.api.menu.bo.MenuBO;
import com.slipper.system.api.menu.service.IMenuSv;

import java.util.List;
import java.util.Set;

@RestController
public class MenuSv implements IMenuSv {
    @Resource
    private MenuService menuService;
    @Resource
    private MenuPrivilegeService menuPrivilegeService;
    
    @Override
    public Result<MenuBO> queryBy(String id){
        return ResultUtil.successResult(menuService.queryBy(id));
    }
    
    @Override
    public Result<List<MenuBO>> queryPage(MenuBO bo){
        return ResultUtil.successResult(menuService.queryPage(bo));
    }
    
    @Override
    public Result<?> save(MenuBO bo){
        return ResultUtil.saveResult(menuService.save(bo), bo);
    }
    
    @Override
    public Result<?> delete(MenuBO bo){
        return ResultUtil.deleteResult(menuService.delete(bo));
    }
    
    @Override
    public Result<List<MenuBO>> queryUserMenus(MenuBO bo) {
        return ResultUtil.successResult(menuService.queryUserMenus(bo));
    }

    @Override
    public Result<?> updateParentId(MenuBO bo) {
        return ResultUtil.saveResult(menuService.updateParentId(bo), bo);
    }

    @Override
    public Result<?> updateConfig(MenuBO bo) {
        menuService.updateJson(bo);
        menuPrivilegeService.save(bo.getId(), bo.getPrivileges());
        return ResultUtil.successResult("保存成功！", bo);
    }

    @Override
    public Result<Set<String>> queryPermitUrl(MenuBO bo) {
        return ResultUtil.successResult(menuService.queryPermitUrl(bo));
    }

    @Override
    public Result<List<MenuBO>> queryList(MenuBO bo) {
        return ResultUtil.successResult(this.menuService.queryList(bo));
    }
}
